import 'package:flutter/material.dart';
import 'package:hm_pda_app/config/http_request.dart';
import 'package:hm_pda_app/components/loading_overlay.dart';

class PackingGoods extends StatefulWidget {
  const PackingGoods({super.key});
  @override
  State<PackingGoods> createState() => _PackingGoodsState();
}

// 单选的数据源
enum SingingCharacter { lafayette, jefferson, noprint }

class _PackingGoodsState extends State<PackingGoods> {
  final _formKey = GlobalKey<FormState>(); // 表单Key
  final GlobalKey<_PackingGoodsState> formKey = GlobalKey<_PackingGoodsState>();
  final _pickController = TextEditingController();
  final _skuController = TextEditingController();
  final _pickFocusNode = FocusNode();
  final _skuFocusNode = FocusNode();
  // 水果列表
  final List<Map<String, String>> _fruits = [];
  SingingCharacter? _character = SingingCharacter.lafayette;
  InfoItem? _infoData;
  // 下拉选择样例
  String? _selectedFruit; // 当前选中的水果，初始为null

  @override
  void initState() {
    super.initState();
    _getPackageMethods();
    _infoData = InfoItem(
      id: '',
      pickingNo: '',
      packingUserName: '',
      orderType: '',
      strategyBusinessType: '',
      orderTotal: '',
      unOrderTotal: '',
      skuTotal: '',
      unSkuTotal: '',
      skuCode: '',
      packageSkuId: '',
      priteType: '',
      pictureUrl: '',
      remark: '',
      shippingChannelRules: '',
      finishList: [],
      unFinishList: [],
    );
  }

  // 获取信息
  void _getInfoRequest(BuildContext context) async {
    if (_pickController.text.isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('请输入拣货单号'), duration: Duration(seconds: 2)),
      );
      return;
    }

    try {
      LoadingOverlay.show(context);
      final response = await HttpUtil.get(
        '/storage/outboundShippingPackLabel/get?pickingNo=${_pickController.text}',
      );
      print('获取信息---$response');
      if (response.data != null) {
        final dataMap = response.data as Map<String, dynamic>;
        if (dataMap['id'] == null) {
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text('暂无数据，请输入有效的单号'),
              duration: Duration(seconds: 2),
            ),
          );
          return;
        } else {
          setState(() {
            _infoData = InfoItem.fromJson(dataMap);
          });
        }
      }
    } catch (e) {
      print('报错---$e');
    } finally {
      LoadingOverlay.hide();
    }
  }

  // // 拣货类型枚举转换
  // String _getPickingType(String type) {
  //   switch (type) {
  //     case 'order':
  //       return '按单分拣';
  //     case 'concentrated':
  //       return '集中分拣';
  //     case 'shop_car':
  //       return '拣货小车';
  //     case 'storage_lend_order':
  //       return '借出单';
  //     default:
  //       return '';
  //   }
  // }

  // 订单类型
  String _getOrderType(String? type) {
    if (type == null) return '';
    switch (type) {
      case '0':
        return '一票一件';
      case '1':
        return '一票一件多个';
      case '2':
        return '一票多件多个';
      default:
        return '';
    }
  }

  // 邮递类型
  String _getMailType(String? type) {
    switch (type) {
      case 'DirectMail':
        return '直邮';
      case 'OverseasWarehouse':
        return '海外仓';
      case 'StockTakeResultShortage':
        return '盘亏';
      case 'StorageImSkuExchange':
        return 'SKU换货单';
      case 'StorageLendOrder':
        return 'SKU借出单';
      default:
        return '';
    }
  }

  // 获取包材
  Future<void> _getPackageMethods() async {
    try {
      final response = await HttpUtil.post(
        '/storage/outboundShippingPackLabel/package/list',
        data: {'pageSize': 99999, 'pageNum': 1},
      );

      final dataMap = response.data as Map<String, dynamic>;
      if (dataMap['rows'] != null && dataMap['rows'] is List) {
        final rows = dataMap['rows'] as List<dynamic>;
        final List<Map<String, String>> processedRows = [];

        if (rows.isNotEmpty) {
          for (var e in rows) {
            processedRows.add({
              'label': e['chineseName']?.toString() ?? '',
              'value': e['skuId']?.toString() ?? '',
            });
          }
          setState(() {
            _fruits.clear();
            //  _fruits.addAll(processedRows);
          });
          print('获取包材---,$_fruits');
        }
      }
    } catch (e) {
      print('报错---$e');
    } finally {}
  }

  // 提交
  Future<void> _submitRequest(BuildContext context) async {
    try {
      if (!_formKey.currentState!.validate()) {
        // 表单验证通过，可以提交数据
        print('提交数据校验不通过');
        return;
      }
      LoadingOverlay.show(context);
      final response = await HttpUtil.post(
        '/storage/outboundShippingPackLabel/change/completePicking',
        data: {
          'finishList': _infoData?.finishList,
          'packingUserId': '',
          'pickingNo': _infoData?.pickingNo,
          'unFinishList': _infoData?.unFinishList,
        },
      );
      print('提交数据---$response');
      if (response.code != 200) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('提交报错：${response.message}'),
            duration: Duration(seconds: 3),
          ),
        );

        // 清空表单
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('提交成功'), duration: Duration(seconds: 3)),
        );
        _pickFocusNode.requestFocus();
      }
    } catch (e) {
      print('报错---$e');
    } finally {
      LoadingOverlay.hide();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('打包贴标')),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(1),
        child: Form(
          key: _formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              // 收货单号
              Row(
                children: [
                  Expanded(
                    flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('拣货单', isRequired: true),
                    ),
                  ),
                  Expanded(
                    flex: 5,
                    child: Align(
                      alignment: Alignment.topLeft,
                      child: TextFormField(
                        controller: _pickController,
                        // enabled: _infoData?.id == null || _infoData?.id == '',
                        decoration: _buildInputDecoration(
                          hintText: '',
                          controller: _pickController,
                          suffixIcon: ValueListenableBuilder<TextEditingValue>(
                            valueListenable: _pickController,
                            builder: (context, value, child) {
                              return value.text.isEmpty
                                  ? SizedBox.shrink()
                                  : IconButton(
                                      icon: Icon(Icons.clear, size: 20),
                                      onPressed: () {
                                        _pickController.clear();
                                      },
                                    );
                            },
                          ),
                        ),
                        focusNode: _pickFocusNode,
                        onFieldSubmitted: (value) {
                          //  _getInfoRequest();
                          _getInfoRequest(context);
                          print('回车执行');
                        },
                      ),
                    ),
                  ),
                  // 按钮部分
                  Expanded(
                    flex: 2,
                    child: Align(
                      alignment: Alignment.centerRight,
                      child: ElevatedButton(
                        onPressed: () {
                          // _getInfoRequest();
                          _getInfoRequest(context);
                        },
                        style: ElevatedButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(2),
                          ),
                          padding: EdgeInsets.all(12),
                          minimumSize: Size(0, 0),
                          backgroundColor: Colors.blue,
                          foregroundColor: Colors.white,
                          tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                        ),

                        child: Text('查询'),
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              // 收货单号
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '打包员：${_infoData?.packingUserName}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '订单类型：${_getOrderType(_infoData?.orderType?.toString())}/${_getMailType(_infoData?.strategyBusinessType)}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '订单总数：${_infoData?.orderTotal}',
                        isRequired: false,
                      ),
                    ),
                  ),
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '已完成数：${_infoData?.unOrderTotal}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        'SKU总数：${_infoData?.skuTotal}',
                        isRequired: false,
                      ),
                    ),
                  ),
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '已完成数：${_infoData?.unSkuTotal}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    flex: 1,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child:
                          _infoData?.pictureUrl != null &&
                              _infoData!.pictureUrl!.isNotEmpty
                          ? GestureDetector(
                              onTap: () {
                                _showImagePreview(
                                  context,
                                  _infoData!.pictureUrl!,
                                );
                              },
                              child: Image(
                                image: NetworkImage(_infoData!.pictureUrl!),
                                width: 100,
                                height: 100,
                                errorBuilder: (context, error, stackTrace) {
                                  return Container(
                                    width: 100,
                                    height: 100,
                                    color: Colors.grey[200],
                                    child: Icon(
                                      Icons.image_not_supported,
                                      size: 50,
                                      color: Colors.grey[400],
                                    ),
                                  );
                                },
                              ),
                            )
                          : Container(
                              width: 100,
                              height: 100,
                              color: Colors.grey[200],
                              child: Icon(
                                Icons.image,
                                size: 50,
                                color: Colors.grey[400],
                              ),
                            ),
                    ),
                  ),
                  Expanded(
                    flex: 4,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel('SKU', isRequired: true),
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child: Align(
                                  alignment: Alignment.topLeft,
                                  child: TextFormField(
                                    controller: _skuController,
                                    validator: (value) {
                                      if (value == null || value.isEmpty) {
                                        return '请输入SKU编码';
                                      }

                                      return null; // 返回 null 表示验证通过
                                    },
                                    // enabled:
                                    //     _infoData?.id != null ||
                                    //     _infoData?.id != '',
                                    decoration: _buildInputDecoration(
                                      hintText: '请输入SKU编码',
                                      controller: _skuController,

                                      suffixIcon:
                                          ValueListenableBuilder<
                                            TextEditingValue
                                          >(
                                            valueListenable: _skuController,
                                            builder: (context, value, child) {
                                              return value.text.isEmpty
                                                  ? SizedBox.shrink()
                                                  : IconButton(
                                                      icon: Icon(
                                                        Icons.clear,
                                                        size: 20,
                                                      ),
                                                      onPressed: () {
                                                        _skuController.clear();
                                                      },
                                                    );
                                            },
                                          ),
                                    ),
                                    focusNode: _skuFocusNode,
                                    onFieldSubmitted: (value) {
                                      //  _getInfoRequest();
                                      //  _getInfoRequest(context);
                                      print('回车执行');
                                    },
                                  ),
                                ),
                              ),
                            ],
                          ),
                          const Divider(
                            height: 2, // 容器总高度2像素
                            thickness: 1, // 分割线厚度5像素
                            indent: 0, // 左侧缩进20像素
                            endIndent: 0, // 右侧无缩进
                            color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
                          ),
                          Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel('包材', isRequired: false),
                                ),
                              ),
                              Expanded(
                                flex: 5,
                                child: DropdownButton<String>(
                                  value: _selectedFruit, // 当前选中的值
                                  hint: Text('请选择'), // 当没有选中任何项目时显示的提示
                                  isExpanded: true, // 让下拉框占满可用宽度

                                  onChanged: (String? newValue) {
                                    setState(() {
                                      _selectedFruit = newValue; // 更新选中的值
                                    });
                                  },
                                  items: _fruits.map<DropdownMenuItem<String>>((
                                    Map<String, String> fruit,
                                  ) {
                                    return DropdownMenuItem<String>(
                                      value: fruit['value'],
                                      child: SizedBox(
                                        width: double.infinity,
                                        child: Text(
                                          fruit['label']!,
                                          overflow: TextOverflow.ellipsis,
                                          maxLines: 1,
                                          softWrap: false,
                                        ),
                                      ),
                                    );
                                  }).toList(),
                                ),
                              ),
                            ],
                          ),
                          const Divider(
                            height: 2, // 容器总高度2像素
                            thickness: 1, // 分割线厚度5像素
                            indent: 0, // 左侧缩进20像素
                            endIndent: 0, // 右侧无缩进
                            color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
                          ),
                          Row(
                            children: [
                              Expanded(
                                flex: 2,
                                child: Align(
                                  alignment: Alignment.centerLeft,
                                  child: _buildLabel('记住包材', isRequired: false),
                                ),
                              ),
                              Expanded(
                                flex: 4,
                                child: DropdownButton<String>(
                                  value: _selectedFruit, // 当前选中的值
                                  hint: Text('请选择'), // 当没有选中任何项目时显示的提示
                                  onChanged: (String? newValue) {
                                    setState(() {
                                      _selectedFruit = newValue; // 更新选中的值
                                    });
                                  },
                                  items: _fruits.map<DropdownMenuItem<String>>((
                                    Map<String, String> fruit,
                                  ) {
                                    return DropdownMenuItem<String>(
                                      value: fruit['value'],
                                      child: Text(fruit['label']!),
                                    );
                                  }).toList(),
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              // 收货单号
              Row(
                children: [
                  Expanded(
                    flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel('SKU打印', isRequired: false),
                    ),
                  ),
                  Expanded(
                    flex: 10,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: RadioGroup<SingingCharacter>(
                        groupValue: _character,
                        onChanged: (SingingCharacter? value) {
                          setState(() {
                            _character = value;
                          });
                        },
                        child: Row(
                          children: [
                            Expanded(
                              // flex: 2,
                              child: Align(
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  children: [
                                    Radio<SingingCharacter>(
                                      value: SingingCharacter.lafayette,
                                    ),
                                    SizedBox(width: 0),
                                    Text('全部'),
                                  ],
                                ),
                              ),
                            ),
                            Expanded(
                              //  flex: 3,
                              child: Align(
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  children: [
                                    Radio<SingingCharacter>(
                                      value: SingingCharacter.jefferson,
                                    ),
                                    SizedBox(width: 1),
                                    Text('逐张'),
                                  ],
                                ),
                              ),
                            ),
                            Expanded(
                              //flex: 3,
                              child: Align(
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  children: [
                                    Radio<SingingCharacter>(
                                      value: SingingCharacter.noprint,
                                    ),
                                    SizedBox(width: 1),
                                    Text('不打印'),
                                  ],
                                ),
                              ),
                            ),

                            // ListTile(
                            //   title: Text('不打印'),
                            //   leading: Radio<SingingCharacter>(
                            //     value: SingingCharacter.jefferson,
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              // 收货单号
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '渠道规则: ${_infoData?.shippingChannelRules}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
              Row(
                children: [
                  Expanded(
                    //flex: 2,
                    child: Align(
                      alignment: Alignment.centerLeft,
                      child: _buildLabel(
                        '订单备注：${_infoData?.remark}',
                        isRequired: false,
                      ),
                    ),
                  ),
                ],
              ),
              // SizedBox(height: 5),
              const Divider(
                height: 2, // 容器总高度2像素
                thickness: 1, // 分割线厚度5像素
                indent: 0, // 左侧缩进20像素
                endIndent: 0, // 右侧无缩进
                color: Color.fromARGB(255, 109, 108, 108), // 黑色分割线
              ),
            ],
          ),
        ),
      ),
      bottomNavigationBar: DecoratedBox(
        decoration: BoxDecoration(color: const Color.fromARGB(255, 77, 76, 76)),
        child: SizedBox(
          width: double.infinity,
          height: 50,
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: Row(
              children: [
                Expanded(
                  child: SizedBox(
                    height: 40,
                    child: OutlinedButton(
                      onPressed: () {
                        // 取消操作，重置表单
                        // _resetForm();
                        // final formState = context
                        //     .findAncestorStateOfType<IncomingGoodsFormState>();
                        // formState?._resetForm();
                      },
                      style: OutlinedButton.styleFrom(
                        foregroundColor: Colors.white,
                        backgroundColor: Colors.grey[600],
                        side: BorderSide.none,
                        textStyle: const TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w500,
                        ),
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(12),
                        ),
                        elevation: 1,
                      ),
                      child: const Text('清除'),
                    ),
                  ),
                ),
                const SizedBox(width: 12),

                Expanded(
                  child: (_infoData?.id == null || _infoData!.id!.isEmpty)
                      ? Text('')
                      : SizedBox(
                          height: 40,
                          child: ElevatedButton(
                            onPressed: () {
                              _submitRequest(context);
                            },
                            style: ElevatedButton.styleFrom(
                              backgroundColor: Colors.blue[600],
                              foregroundColor: Colors.white,
                              textStyle: const TextStyle(
                                fontSize: 16,
                                fontWeight: FontWeight.w600,
                              ),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                              elevation: 3,
                              // shadowColor: Colors.blue.withOpacity(0.3),
                            ),
                            child: const Text('提交'),
                          ),
                        ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

void _showImagePreview(BuildContext context, String imageUrl) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return Dialog(
        backgroundColor: Colors.transparent,
        child: Stack(
          children: [
            Center(
              child: InteractiveViewer(
                panEnabled: true, // 允许拖拽
                boundaryMargin: EdgeInsets.all(20),
                minScale: 0.1,
                maxScale: 6.0,
                child: SizedBox(
                  width: MediaQuery.of(context).size.width * 0.9,
                  child: Image.network(
                    imageUrl,
                    fit: BoxFit.contain,
                    errorBuilder: (context, error, stackTrace) {
                      return Container(
                        padding: EdgeInsets.all(20),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            Icon(Icons.error, size: 50, color: Colors.white),
                            SizedBox(height: 10),
                            Text(
                              '图片加载失败',
                              style: TextStyle(color: Colors.white),
                            ),
                          ],
                        ),
                      );
                    },
                  ),
                ),
              ),
            ),
            Positioned(
              top: 40,
              right: 20,
              child: GestureDetector(
                onTap: () => Navigator.of(context).pop(),
                child: Container(
                  width: 40,
                  height: 40,
                  decoration: BoxDecoration(
                    color: Colors.black54,
                    shape: BoxShape.circle,
                  ),
                  child: Icon(Icons.close, color: Colors.white, size: 24),
                ),
              ),
            ),
          ],
        ),
      );
    },
  );
}

// 构建标签文本
Widget _buildLabel(String text, {bool isRequired = false}) {
  return SizedBox(
    // width: 200,
    child: Padding(
      padding: EdgeInsets.symmetric(horizontal: 2),
      child: Text(
        text,
        style: TextStyle(
          fontWeight: FontWeight.w500,
          fontSize: 16,
          color: isRequired ? Colors.red : Colors.grey[700],
        ),
      ),
    ),
  );
}

// 构建输入框装饰
InputDecoration _buildInputDecoration({
  required String hintText,
  required TextEditingController controller,
  Widget? suffixIcon,
}) {
  print('controller ${controller.text}');
  return InputDecoration(
    hintText: hintText,
    contentPadding: EdgeInsets.zero, // 设置上下左右内边距都为0
    // prefixIcon: Icon(prefixIcon, color: Colors.grey[600]),
    suffixIcon: suffixIcon,
    hintStyle: TextStyle(color: Colors.grey[500]),
    // isDense: true 属性用于减少输入框的垂直高度，使其更紧凑
    // 当设置为 true 时，会减少内边距，让输入框看起来更小更密集
    // 适用于需要节省空间或创建更紧凑布局的场景
    // isDense: true,
    filled: true,
    fillColor: Colors.grey[50],

    // suffixIcon: controller.text.isNotEmpty
    //             ? IconButton(
    //                 icon: Icon(Icons.clear, size: 20),
    //                 onPressed: () {
    //                   controller.clear();
    //                   // 需要通知父组件状态更新
    //                   if (mounted) {
    //                     setState(() {});
    //                   }
    //                 },
    //               )
    //             : null,
    border: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.grey[300]!),
    ),
    enabledBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.grey[300]!),
    ),
    focusedBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.blue, width: 2),
    ),
    errorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.red),
    ),
    focusedErrorBorder: OutlineInputBorder(
      borderRadius: BorderRadius.circular(8),
      borderSide: BorderSide(color: Colors.red, width: 2),
    ),
  );
}

// 详情信息
class InfoItem {
  final String? id;
  final String? pickingNo;
  final String? packingUserName;
  final String? orderType;
  final String? strategyBusinessType;
  final String? orderTotal;
  final String? unOrderTotal;
  final String? skuTotal;
  final String? unSkuTotal;
  final String? skuCode;
  final String? packageSkuId;
  final String? priteType;
  final String? pictureUrl;
  final String? remark;
  final String? shippingChannelRules;
  final List? finishList;
  final List? unFinishList;

  InfoItem({
    this.id,
    this.pickingNo,
    this.packingUserName,
    this.orderType,
    this.strategyBusinessType,
    this.orderTotal,
    this.packageSkuId,
    this.priteType,
    this.skuCode,
    this.skuTotal,
    this.unOrderTotal,
    this.unSkuTotal,
    this.pictureUrl,
    this.remark,
    this.shippingChannelRules,
    this.finishList,
    this.unFinishList,
  });
  factory InfoItem.fromJson(Map<String, dynamic> json) {
    return InfoItem(
      id: json['id']?.toString() ?? '',
      pickingNo: json['pickingNo']?.toString() ?? '',
      packingUserName: json['packingUserName']?.toString() ?? '',
      orderType: json['orderType']?.toString() ?? '',
      strategyBusinessType: json['strategyBusinessType']?.toString() ?? '',
      orderTotal: json['orderTotal']?.toString() ?? '',
      packageSkuId: json['packageSkuId']?.toString() ?? '',
      priteType: json['priteType']?.toString() ?? '',
      skuCode: json['skuCode']?.toString() ?? '',
      skuTotal: json['skuTotal']?.toString() ?? '',
      unOrderTotal: json['unOrderTotal']?.toString() ?? '',
      unSkuTotal: json['unSkuTotal']?.toString() ?? '',
      pictureUrl: json['pictureUrl'] ?? '',
      remark: json['remark'] ?? '',
      shippingChannelRules: json['shippingChannelRules'] ?? '',
      finishList: json['finishList'] ?? [],
      unFinishList: json['unFinishList'] ?? [],
    );
  }
}
